//
//  LoginVC.m
//  ChangJiuGroup
//
//  Created by Hank on 2017/11/16.
//  Copyright © 2017年 周昊. All rights reserved.
//

#import "LoginVC.h"
#import "UIImage-Extension.h"
#import "DrCorner.h"
#import "UIButton+Expand.h"

@interface LoginVC ()<UITextFieldDelegate>
// logo顶部
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *logoTop;
// 用户名顶部
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *userNameTop;
// 登陆按钮顶部
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *loginBtnTop;

@end

@implementation LoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置界面属性
    [self setViewAttribute];
    // 设置圆角
    [self setRadius];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

// 设置界面属性
- (void)setViewAttribute
{
    self.view.backgroundColor = [UIColor whiteColor];
    // iphone5布局情况
    if (iPhone5) {
        self.logoTop.constant = 94;
        self.userNameTop.constant = 40;
        self.loginBtnTop.constant = 40;
    }
}
// 取消第一响应者(收回键盘)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [_passwordTF resignFirstResponder];
    [_userNameTF resignFirstResponder];
}

#pragma mark - Radius
// 设置圆角
- (void)setRadius
{
    [self.loginBtn radiusBtn:3 backgroundColor:DefaultGray borderWidth:0 borderColor:[UIColor clearColor]];
}

// 请求数据
- (void)requestData
{
    //    if (JudgeStrEqualNull(_userNameTF.text)) {
    //        [MBProgressHUD showError:@"请输入用户名"];
    //        return;
    //    }else if (JudgeStrEqualNull(_passwordTF.text)) {
    //        [MBProgressHUD showError:@"请输入密码"];
    //        return;
    //    }
    //    NSDictionary *info = @{@"loginname":_userNameTF.text,@"pwd":_passwordTF.text};
    //    [[CSSManager getAuthOperator] postApplogin:info tag:self successBlock:^(id respondObject) {
    //        [AppDelegate showMain];
    //    } failureBlock:^(id respondObject) {
    //        [MBProgressHUD showError:@"登陆失败"];
    //    }];
    //    测试使用
    [AppDelegate showMain];
}

#pragma mark - Action
// 加密按钮 Action
- (IBAction)secureTextBtnAction:(UIButton *)sender
{
    if (_passwordTF.secureTextEntry) {
        _passwordTF.secureTextEntry = NO;
        _eyesImage.image = [UIImage imageNamed:@"login_openEyes"];
    }else{
        _passwordTF.secureTextEntry = YES;
        _eyesImage.image = [UIImage imageNamed:@"login_closeEyes"];
    }
}
// 登陆按钮 Action
- (IBAction)loginBtnAction:(UIButton *)sender
{
    // 请求数据
    [self requestData];
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    // 请求数据
    [self requestData];
    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
